SELECT f.rdb$relation_name AS Table_Name, f.rdb$field_name Field_Name,
	CASE fd.RDB$FIELD_TYPE
	WHEN 261 THEN 'BLOB'
	WHEN 14 THEN 'CHAR'
	WHEN 40 THEN 'CSTRING'
	WHEN 11 THEN 'D_FLOAT'
	WHEN 27 THEN 'DOUBLE'
	WHEN 10 THEN 'FLOAT'
	WHEN 16 THEN 'INT64'
	WHEN 8 THEN 'INTEGER'
	WHEN 9 THEN 'QUAD'
	WHEN 7 THEN 'SMALLINT'
	WHEN 12 THEN 'DATE'
	WHEN 13 THEN 'TIME'
	WHEN 35 THEN 'TIMESTAMP'
	WHEN 37 THEN 'VARCHAR'
	ELSE 'UNKNOWN'
    END AS Field_Type, fd.RDB$FIELD_LENGTH / 4 AS Char_Field_Length -- Account for the default UTF-8 storage (4 bytes per character)

FROM rdb$relation_fields f
JOIN rdb$relations r ON f.rdb$relation_name = r.rdb$relation_name
AND r.rdb$view_blr IS NULL
AND (r.rdb$system_flag IS NULL OR r.rdb$system_flag = 0)
LEFT JOIN RDB$FIELDS fd ON f.RDB$FIELD_SOURCE = fd.RDB$FIELD_NAME
ORDER BY 1, f.rdb$field_position;